package 江苏大学;

import com.alibaba.excel.EasyExcel;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import 南京理工大学.NJuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class JSu {
    public static void main(String[] args) throws IOException {
        JSuBean jSuBean = null;
        List<JSuBean> jSuBeans = new ArrayList<>();
        String att2 = new String();
        String Url = "https://eie.ujs.edu.cn/szdw/bsds.htm";
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
        Elements content = post.getElementsByClass("content");
        for (Element element : content) {
            for (Element p : element.getElementsByTag("span")) {
                jSuBean = new JSuBean();
//                System.out.println(p.text());
//                System.out.println(p.getElementsByTag("a").attr("href"));
//                System.out.println(p.text());
                String attr = p.getElementsByTag("a").attr("href");
                if (attr.equals("")) {
                } else {
                    att2 = attr.substring(3, attr.length());
                }
                Connection connect1 = Jsoup.connect("https://eie.ujs.edu.cn/" + att2);
                Document post1 = connect1.post();
                jSuBean.setT_name(post1.getElementsByClass("page_tit").text());
                jSuBean.setInfo(post1.getElementsByClass("v_news_content").text());
//                System.out.println(post1.getElementsByClass("page_tit").text());//name
//                System.out.println(post1.getElementsByClass("v_news_content").text());//info
                jSuBeans.add(jSuBean);
            }
        }
        EasyExcel.write("src/JSu.xlsx", JSuBean.class).sheet("user").doWrite(jSuBeans);

    }
}
